package com.example.file_management.mapper.user;

import com.example.file_management.pojo.user.Group;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface GroupMapper {

    // 查询所有组
    @Select("SELECT * FROM group_table")
    List<Group> findAllGroups();

    // 根据ID查询组
    @Select("SELECT * FROM group_table WHERE group_id = #{groupId}")
    Group findGroupById(@Param("groupId") Long groupId);

    // 根据组名查询组ID
    @Select("SELECT group_id FROM group_table WHERE group_name = #{groupName}")
    Integer findGroupIdByName(@Param("groupName") String groupName);


    // 插入组信息
    @Insert("INSERT INTO groups (group_name, role_id, created_at) VALUES (#{groupName}, #{roleId}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "group_id")
    int insertGroup(Group group);;

    // 更新组信息
    @Update("UPDATE group_table SET group_name = #{groupName} WHERE group_id = #{groupId}")
    int updateGroup(Group group);

    // 删除组
    @Delete("DELETE FROM group_table WHERE group_id = #{groupId}")
    int deleteGroup(@Param("groupId") Long groupId);
    @Select("SELECT COUNT(*) FROM groups WHERE group_name = #{groupName}")
    boolean isGroupNameExists(String groupName);
}
